// HTTP状态码
const HTTP_STATUS = {
  OK: 200,
  CREATED: 201,
  NO_CONTENT: 204,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  CONFLICT: 409,
  UNPROCESSABLE_ENTITY: 422,
  TOO_MANY_REQUESTS: 429,
  INTERNAL_SERVER_ERROR: 500,
  BAD_GATEWAY: 502,
  SERVICE_UNAVAILABLE: 503
}

// 错误代码
const ERROR_CODES = {
  // 认证相关
  INVALID_CREDENTIALS: 'INVALID_CREDENTIALS',
  TOKEN_EXPIRED: 'TOKEN_EXPIRED',
  TOKEN_INVALID: 'TOKEN_INVALID',
  ACCESS_DENIED: 'ACCESS_DENIED',
  
  // 用户相关
  USER_NOT_FOUND: 'USER_NOT_FOUND',
  USER_ALREADY_EXISTS: 'USER_ALREADY_EXISTS',
  
  // AI配置相关
  AI_CONFIG_NOT_FOUND: 'AI_CONFIG_NOT_FOUND',
  AI_CONFIG_INVALID: 'AI_CONFIG_INVALID',
  AI_API_ERROR: 'AI_API_ERROR',
  AI_API_TIMEOUT: 'AI_API_TIMEOUT',
  
  // 对话相关
  CHAT_SESSION_NOT_FOUND: 'CHAT_SESSION_NOT_FOUND',
  MESSAGE_NOT_FOUND: 'MESSAGE_NOT_FOUND',
  
  // 验证相关
  VALIDATION_ERROR: 'VALIDATION_ERROR',
  MISSING_REQUIRED_FIELD: 'MISSING_REQUIRED_FIELD',
  
  // 系统相关
  DATABASE_ERROR: 'DATABASE_ERROR',
  ENCRYPTION_ERROR: 'ENCRYPTION_ERROR',
  RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
  INTERNAL_ERROR: 'INTERNAL_ERROR'
}

// 用户角色
const USER_ROLES = {
  ADMIN: 'admin',
  STUDENT: 'student'
}

// 令牌类型
const TOKEN_TYPES = {
  ACCESS: 'access',
  REFRESH: 'refresh'
}

// 消息角色
const MESSAGE_ROLES = {
  USER: 'user',
  ASSISTANT: 'assistant',
  SYSTEM: 'system'
}

// AI模型配置
const AI_MODELS = {
  DEEPSEEK_V25: 'deepseek-ai/DeepSeek-V2.5',
  QWEN_72B: 'Qwen/Qwen2.5-72B-Instruct',
  LLAMA_70B: 'meta-llama/Meta-Llama-3.1-70B-Instruct'
}

// AI提供商
const AI_PROVIDERS = {
  SILICONFLOW: 'siliconflow',
  OPENAI: 'openai',
  DEEPSEEK: 'deepseek'
}

// AI提供商配置
const AI_PROVIDER_CONFIGS = {
  [AI_PROVIDERS.SILICONFLOW]: {
    name: 'SiliconFlow',
    baseUrl: 'https://api.siliconflow.cn/v1',
    models: [AI_MODELS.DEEPSEEK_V25, AI_MODELS.QWEN_72B, AI_MODELS.LLAMA_70B]
  },
  [AI_PROVIDERS.OPENAI]: {
    name: 'OpenAI',
    baseUrl: 'https://api.openai.com/v1',
    models: ['gpt-3.5-turbo', 'gpt-4', 'gpt-4-turbo']
  },
  [AI_PROVIDERS.DEEPSEEK]: {
    name: 'DeepSeek',
    baseUrl: 'https://api.deepseek.com/v1',
    models: ['deepseek-chat', 'deepseek-coder']
  }
}

// 系统配置键
const SYSTEM_CONFIG_KEYS = {
  MAX_CHAT_SESSIONS_PER_USER: 'max_chat_sessions_per_user',
  MAX_MESSAGES_PER_SESSION: 'max_messages_per_session',
  DEFAULT_AI_MODEL: 'default_ai_model',
  ENABLE_REGISTRATION: 'enable_registration',
  MAX_MESSAGE_LENGTH: 'max_message_length'
}

// 默认系统配置值
const DEFAULT_SYSTEM_CONFIGS = {
  [SYSTEM_CONFIG_KEYS.MAX_CHAT_SESSIONS_PER_USER]: '50',
  [SYSTEM_CONFIG_KEYS.MAX_MESSAGES_PER_SESSION]: '1000',
  [SYSTEM_CONFIG_KEYS.DEFAULT_AI_MODEL]: AI_MODELS.DEEPSEEK_V25,
  [SYSTEM_CONFIG_KEYS.ENABLE_REGISTRATION]: 'true',
  [SYSTEM_CONFIG_KEYS.MAX_MESSAGE_LENGTH]: '4000'
}

// 缓存键前缀
const CACHE_KEYS = {
  USER_SESSION: 'user_session:',
  AI_CONFIG: 'ai_config:',
  CHAT_SESSION: 'chat_session:',
  SYSTEM_CONFIG: 'system_config:'
}

// 缓存过期时间（秒）
const CACHE_TTL = {
  USER_SESSION: 24 * 60 * 60, // 24小时
  AI_CONFIG: 60 * 60, // 1小时
  CHAT_SESSION: 30 * 60, // 30分钟
  SYSTEM_CONFIG: 60 * 60 // 1小时
}

// 限流配置
const RATE_LIMITS = {
  AUTH: {
    windowMs: 15 * 60 * 1000, // 15分钟
    max: 5 // 最多5次尝试
  },
  API: {
    windowMs: 15 * 60 * 1000, // 15分钟
    max: 100 // 最多100次请求
  },
  AI_CALL: {
    windowMs: 60 * 1000, // 1分钟
    max: 10 // 最多10次AI调用
  }
}

// 文件上传限制
const UPLOAD_LIMITS = {
  MAX_FILE_SIZE: 5 * 1024 * 1024, // 5MB
  ALLOWED_TYPES: ['image/jpeg', 'image/png', 'image/gif', 'text/plain']
}

// 正则表达式
const REGEX = {
  EMAIL: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
  PASSWORD: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{8,}$/,
  USERNAME: /^[a-zA-Z0-9_]{3,20}$/,
  UUID: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
}

// 系统消息模板
const SYSTEM_MESSAGES = {
  FRONTEND_ASSISTANT: '你是一个专业的前端开发助手，专门帮助学生学习前端技术，包括HTML、CSS、JavaScript、Vue.js等。请用简洁明了的语言回答问题，并提供实用的代码示例。',
  GENERAL_ASSISTANT: '你是一个有用的AI助手，请根据用户的问题提供准确、有用的回答。'
}

// 导出所有常量
module.exports = {
  HTTP_STATUS,
  ERROR_CODES,
  USER_ROLES,
  TOKEN_TYPES,
  MESSAGE_ROLES,
  AI_MODELS,
  AI_PROVIDERS,
  AI_PROVIDER_CONFIGS,
  SYSTEM_CONFIG_KEYS,
  DEFAULT_SYSTEM_CONFIGS,
  CACHE_KEYS,
  CACHE_TTL,
  RATE_LIMITS,
  UPLOAD_LIMITS,
  REGEX,
  SYSTEM_MESSAGES
}